<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">
        <div class="layui-form layuimini-form">
            <div class="layui-form-item">
                <label class="layui-form-label">AppId</label>
                <div class="layui-input-block">
                    <input type="text" name="miniprogram_appid" maxlength="18" class="layui-input">
                    <tip>小程序AppID，wx开头18位长度，从公众平台小程序管理页面获取</tip>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">AppSecret</label>
                <div class="layui-input-block">
                    <input type="text" name="miniprogram_appsecret" maxlength="32" class="layui-input">
                    <tip>小程序密钥，32位长度，从公众平台小程序管理页面获取</tip>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use([], function () {
        var $ = layui.jquery,
            layer = layui.layer,
            http = layui.http,
            form = layui.form;

        //拉取信息
        var oldData;
        http.ajaxPost('/admin/Setting/getMiniProgram', {}, function (data) {
            oldData = data;
            $("[name='miniprogram_appid']").val(data.miniprogram_appid);
            $("[name='miniprogram_appsecret']").val(data.miniprogram_appsecret);
        });

        //监听提交
        form.on('submit(saveBtn)', function (formdata) {
            for (let field in formdata.field) {
                if (formdata.field[field] == oldData[field]) {
                    delete formdata.field[field];
                }
            }
            http.ajaxPost('/admin/Setting/saveMiniProgram', formdata.field, function (data) {
                for (let field in formdata.field) {
                    oldData[field] = formdata.field[field];
                }
                layer.msg('保存成功', { time: 1000 }, function () { });
            });
        });
    });
</script>